package com.gjy.concurrency.h1;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.scheduling.support.SimpleTriggerContext;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-05-30 15:16:29
 */
public class PoolTest {

    private static final Logger logger = LoggerFactory.getLogger(PoolTest.class);
    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");

    @Test
    public void test1() {
        String corn = "0/5 * * * * ?";
        CronTrigger cronTrigger = new CronTrigger(corn);

        SimpleTriggerContext context = new SimpleTriggerContext();
        Date date = cronTrigger.nextExecutionTime(context);

        logger.info("now  = {}", FORMAT.format(new Date()));
        logger.info("date = {}", FORMAT.format(date));

        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.initialize();

        scheduler.schedule(() -> {
            logger.info("{}", FORMAT.format(new Date()));
        }, cronTrigger);

    }
}
